// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/firecontrol/api/XfDevicePointApi'

import OneClass from '@api/firecontrol/model/QueryXfDevicePointDetailReq'

const CLIENT = CORE.grpcCLIENT(Client)

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async getOne({ id }, TIP = '查询消防详情') {
    const DTO = CORE.grpcDTO(OneClass, { id })
    const { content = {}, alarmDto = {} } = await CORE.grpc(TIP, CLIENT, 'queryXfDevicePointDetail', DTO)
    return { ...content, alarmDto }
  },
  transOne(obj) {
    if (!CORE.isEmpty(obj.alarmDto)) {
      const { id, alarmTime: time, alarmDetail: name } = obj.alarmDto
      obj.alarmId = id
      obj.alarmContent = `${CORE.timeStr(time)} 产生${name}`.replace(/((告|报)警)?$/, CORE.MAP.ALARM)
    }
    return obj
  },
}
